﻿<div class="panel panel-default">
    <div class="panel-heading">
        <h2 ng-if="!vm.isEditMode">{{::vm.translate.get('Create Cart Pricing Rule')}}</h2>
        <h2 ng-if="vm.isEditMode">{{::vm.translate.get('Edit Cart Pricing Rule')}}</h2>
    </div>
    <div class="panel-body">
        <form name="cartRuleForm" class="form-horizontal">
            <div class="col-sm-offset-2 bg-danger" ng-show="vm.validationErrors">
                <ul>
                    <li ng-repeat="error in vm.validationErrors">{{error}}</li>
                </ul>
            </div>
            <uib-tabset>
                <uib-tab index="0" heading="{{::vm.translate.get('General Information')}}">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('Name')}} *</label>
                        <div class="col-sm-10">
                            <input name="name" ng-model="vm.cartRule.name" class="form-control" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('Description')}}</label>
                        <div class="col-sm-10">
                            <textarea name="description" ng-model="vm.cartRule.description" rows="3" class="form-control" />
                        </div>
                    </div>
                    <div ng-show="false" class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" ng-model="vm.cartRule.isCouponRequired">{{::vm.translate.get('Require coupon code')}}
                                </label>
                            </div>
                        </div>
                    </div>
                    <div ng-show="vm.cartRule.isCouponRequired" class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('Coupon code')}} *</label>
                        <div class="col-sm-10">
                            <input name="couponCode" ng-model="vm.cartRule.couponCode" class="form-control" />
                        </div>
                    </div>
                    <div ng-show="vm.cartRule.isCouponRequired" class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('Usage limit per coupon')}}</label>
                        <div class="col-sm-10">
                            <input name="usageLimitPerCoupon" ng-model="vm.cartRule.usageLimitPerCoupon" class="form-control" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('Usage limit per customer')}}</label>
                        <div class="col-sm-10">
                            <input name="usageLimitPerCustomer" ng-model="vm.cartRule.usageLimitPerCustomer" class="form-control" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('Start')}}</label>
                        <div class="col-sm-10">
                            <p class="input-group">
                                <input type="text" class="form-control" datetime-picker="dd MMM yyyy HH:mm" ng-model="vm.cartRule.startOn" is-open="vm.datePickerStartOn.open" datepicker-options="vm.datePickerStartOn.datepickerOptions" />
                                <span class="input-group-btn">
                                    <button type="button" class="btn btn-default" ng-click="vm.openCalendar($event, 'datePickerStartOn')"><i class="fa fa-calendar"></i></button>
                                </span>
                            </p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('End')}}</label>
                        <div class="col-sm-10">
                            <p class="input-group">
                                <input type="text" class="form-control" datetime-picker="dd MMM yyyy HH:mm" ng-model="vm.cartRule.endOn" is-open="vm.datePickerEndOn.open" datepicker-options="vm.datePickerEndOn.datepickerOptions" />
                                <span class="input-group-btn">
                                    <button type="button" class="btn btn-default" ng-click="vm.openCalendar($event, 'datePickerEndOn')"><i class="fa fa-calendar"></i></button>
                                </span>
                            </p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('Apply')}} *</label>
                        <div class="col-sm-10">
                            <select class="form-control" ng-model="vm.cartRule.ruleToApply">
                                <option value="cart_fixed">{{::vm.translate.get('Fixed amount discount for whole cart')}}</option>
                                <option value="by_percent">{{::vm.translate.get('Percent of product price discount')}}</option>
                                <!--<option value="buy_x_get_y">Buy X Get Y Free (discount amount is Y)</option>-->
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('Discount Amount')}} *</label>
                        <div class="col-sm-10">
                            <input name="discountAmount" ng-model="vm.cartRule.discountAmount" class="form-control" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('Max Discount Amount')}}</label>
                        <div class="col-sm-10">
                            <input name="maxDiscountAmount" ng-model="vm.cartRule.maxDiscountAmount" class="form-control" />
                        </div>
                    </div>
                    <div ng-show="vm.cartRule.ruleToApply == 'buy_x_get_y'" class="form-group">
                        <label class="col-sm-2 control-label">{{::vm.translate.get('Discount Step (Buy X)')}}</label>
                        <div class="col-sm-10">
                            <input name="discountStep" ng-model="vm.cartRule.discountStep" class="form-control" />
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" ng-model="vm.cartRule.isActive">{{::vm.translate.get('Is Active')}}
                                </label>
                            </div>
                        </div>
                    </div>
                </uib-tab>
                <uib-tab index="1" heading="{{::vm.translate.get('Products Selection')}}">
                    <p>{{::vm.translate.get('Select products to apply or leave blank for all products')}}</p>
                    <product-selection-directive model-id="productsSelector" title="{{::vm.translate.get('Add products')}}" selected-products="vm.cartRule.products"></product-selection-directive>
                    <p><button type="button" class="btn btn-default" data-toggle="modal" data-target="#productsSelector">{{::vm.translate.get('Manage Products Selection')}}</button></p>
                    <table class="table table-striped">
                        <tr>
                            <th>{{::vm.translate.get('Name')}}</th>
                            <th class="text-center">{{::vm.translate.get('Is Published')}}</th>
                        </tr>
                        <tr ng-repeat="product in vm.cartRule.products">
                            <td>{{product.name}}</td>
                            <td class="text-center"><i ng-attr-class="{{product.isPublished && 'fa fa-circle' || 'fa fa-circle-o'}}"></i></td>
                        </tr>
                    </table>
                </uib-tab>
            </uib-tabset>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button class="btn btn-primary" ng-click="vm.save()"><span class="glyphicon glyphicon-ok"></span> {{::vm.translate.get('Save')}}</button>
                    <button ui-sref="cart-rules" class="btn btn-default">{{::vm.translate.get('Cancel')}}</button>
                </div>
            </div>
        </form>
    </div>
</div>
